package jm.nj.demo09mian.demo04;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

/*
 * Map集合版本斗地主
 * 1.准备牌
 * 2.洗牌
 * 3.发牌
 * 4.排序
 * 5看牌
 * */
public class DouDizhu {
    public static void main(String[] args) {
        //1.准备牌
        //Map
        HashMap<Integer, String> poker = new HashMap<Integer, String>();
        //List  存储牌序号
        ArrayList<Integer> pokerNum=new ArrayList<Integer>();
        //存储序号的数组
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        //花色
        String[] colors = {"♠", "♥", "♣", "♦"};
        //组装牌

        int i = 0;
        poker.put(i,"大王");
        pokerNum.add(i++);
        poker.put(i,"小王");
        pokerNum.add(i++);

        for (String number : numbers) {
            for (String color : colors) {
                poker.put(i,color+number);
                pokerNum.add(i++);
            }
        }
        System.out.println(poker);
        System.out.println(pokerNum);

        //2.洗牌
        Collections.shuffle(pokerNum);
        System.out.println(pokerNum);

        //3.发牌
        //创建3player  1底牌
        ArrayList<Integer>player01 = new ArrayList<Integer>();
        ArrayList<Integer>player02 = new ArrayList<Integer>();
        ArrayList<Integer>player03 = new ArrayList<Integer>();
        ArrayList<Integer>dipai = new ArrayList<Integer>();

        //利用j%3  分组发牌
        //fori遍历
        for (int j = 0; j < pokerNum.size(); j++) {
            int number = pokerNum.get(j);
            if(j>=51){
                dipai.add(number);
            }
            if(j%3==0){
                player01.add(number);
            }
            if (j%3==1){
                player02.add(number);
            }
            if (j%3==2){
                player03.add(number);
            }
        }
        System.out.println(player01);
        System.out.println(player02);
        System.out.println(player03);
        System.out.println(dipai);

        //4.排序

        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(dipai);


        System.out.println(player01);
        System.out.println(player02);
        System.out.println(player03);
        System.out.println(dipai);

        //5.看牌
        look("小明",poker, player01);
        look("发放表",poker, player02);
        look("fdd",poker, player03);
        look("dipai",poker,dipai);

    }

    private static void look(String name,HashMap<Integer, String> poker, ArrayList<Integer> player01) {
        System.out.print(name+":  ");
        for (Integer integer : player01) {
            String s=poker.get(integer);
            System.out.print(s+" ");
        }
        System.out.println();
    }
}
